﻿<UserControl x:Class="Opds_Viewer.Control.CaptionButtons"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d">
    <UserControl.Resources>

        <ControlTemplate x:Key="ChromeButtonControlTemplate" TargetType="{x:Type ButtonBase}">
            <Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}"
                    Margin="{Binding MarginButton, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
			        Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" 
				    Content="{TemplateBinding Content}" 
				    ContentStringFormat="{TemplateBinding ContentStringFormat}" 
				    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
				    RecognizesAccessKey="True" 
				    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
				    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="#FFADADAD"/>
                    <Setter Property="Opacity" TargetName="Chrome" Value="0.5"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <DataTemplate x:Key="MaximizeButtonControlTemplate">
            <TextBlock x:Name="StateText" TextWrapping="Wrap" Text="1" FontFamily="Webdings"               
                       Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                       FontSize="{Binding FontSize, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="Normal">
                    <Setter TargetName="StateText" Property="Text" Value="1"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="Maximized">
                    <Setter TargetName="StateText" Property="Text" Value="2"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <DataTemplate x:Key="DefaultButtonControlTemplate">
            <TextBlock TextWrapping="Wrap" Text="{TemplateBinding Content}" FontFamily="Webdings"
                       Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                       FontSize="{Binding FontSize, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
        </DataTemplate>

        <Style x:Key="ReduceChromeButtonStyle" TargetType="{x:Type Button}">
            <Style.Resources>
                <Storyboard x:Key="OnMouseDownStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="OnMouseEnterStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="OnMouseLeaveStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </Style.Resources>
            <Setter Property="Background" Value="#00000000"/>
            <Setter Property="BorderBrush" Value="{x:Null}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template" Value="{StaticResource ChromeButtonControlTemplate}"/>
            <Setter Property="Opacity" Value="0.5" />
            <Setter Property="Visibility" Value="Collapsed"/>
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Opacity" Value="0.5"/>
                </Trigger>
                <DataTrigger Binding="{Binding Type, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="Full">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Type, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="ReduceClose">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <EventTrigger RoutedEvent="Mouse.PreviewMouseDown">
                    <BeginStoryboard x:Name="OnMouseDown_BeginStoryboard" Storyboard="{StaticResource OnMouseDownStoryboard}"/>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseEnter">
                    <BeginStoryboard x:Name="OnMouseEnter_BeginStoryboard" Storyboard="{StaticResource OnMouseEnterStoryboard}"/>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseLeave">
                    <BeginStoryboard x:Name="OnMouseLeave_BeginStoryboard" Storyboard="{StaticResource OnMouseLeaveStoryboard}"/>
                </EventTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="MaximizeChromeButtonStyle" TargetType="{x:Type Button}">
            <Style.Resources>
                <Storyboard x:Key="OnMouseDownStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="OnMouseEnterStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="OnMouseLeaveStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </Style.Resources>
            <Setter Property="Background" Value="#00000000"/>
            <Setter Property="BorderBrush" Value="{x:Null}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template" Value="{StaticResource ChromeButtonControlTemplate}"/>
            <Setter Property="Opacity" Value="0.5" />
            <Setter Property="Visibility" Value="Collapsed"/>
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Opacity" Value="0.5"/>
                </Trigger>
                <DataTrigger Binding="{Binding Type, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="Full">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <EventTrigger RoutedEvent="Mouse.PreviewMouseDown">
                    <BeginStoryboard x:Name="OnMouseDown_BeginStoryboard" Storyboard="{StaticResource OnMouseDownStoryboard}"/>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseEnter">
                    <BeginStoryboard x:Name="OnMouseEnter_BeginStoryboard" Storyboard="{StaticResource OnMouseEnterStoryboard}"/>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseLeave">
                    <BeginStoryboard x:Name="OnMouseLeave_BeginStoryboard" Storyboard="{StaticResource OnMouseLeaveStoryboard}"/>
                </EventTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="CloseChromeButtonStyle" TargetType="{x:Type Button}">
            <Style.Resources>
                <Storyboard x:Key="OnMouseDownStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="OnMouseEnterStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="OnMouseLeaveStoryboard">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </Style.Resources>
            <Setter Property="Background" Value="#00000000"/>
            <Setter Property="BorderBrush" Value="{x:Null}"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template" Value="{StaticResource ChromeButtonControlTemplate}"/>
            <Setter Property="Opacity" Value="0.5" />
            <Setter Property="Visibility" Value="Visible"/>
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Opacity" Value="0.5"/>
                </Trigger>
                <EventTrigger RoutedEvent="Mouse.PreviewMouseDown">
                    <BeginStoryboard x:Name="OnMouseDown_BeginStoryboard" Storyboard="{StaticResource OnMouseDownStoryboard}"/>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseEnter">
                    <BeginStoryboard x:Name="OnMouseEnter_BeginStoryboard" Storyboard="{StaticResource OnMouseEnterStoryboard}"/>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseLeave">
                    <BeginStoryboard x:Name="OnMouseLeave_BeginStoryboard" Storyboard="{StaticResource OnMouseLeaveStoryboard}"/>
                </EventTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="CaptionButtonStyle" TargetType="{x:Type StackPanel}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="Maximized">
                    <Setter Property="Margin" Value="0,10,8,0"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>

    </UserControl.Resources>

    <StackPanel Orientation="Horizontal" Style="{StaticResource CaptionButtonStyle}">
        <Button	Style="{StaticResource ReduceChromeButtonStyle}" Click="MinimizeButtonClick" ContentTemplate="{DynamicResource DefaultButtonControlTemplate}" Content="0" />
        <Button Style="{StaticResource MaximizeChromeButtonStyle}" Click="RestoreButtonClick" ContentTemplate="{DynamicResource MaximizeButtonControlTemplate}"/>
        <Button	Style="{StaticResource CloseChromeButtonStyle}" Click="CloseButtonClick" ContentTemplate="{DynamicResource DefaultButtonControlTemplate}" Content="r" />
    </StackPanel>
</UserControl>
